home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / scribusview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-04-04  |  15.2 KB  |  517 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. /***************************************************************************
  8.                           scribusview.h  -  description
  9.                              -------------------
  10.     begin                : Fre Apr  6 21:47:55 CEST 2001
  11.     copyright            : (C) 2001 by Franz Schmid
  12.     email                : Franz.Schmid@altmuehlnet.de
  13.  ***************************************************************************/
  14.  
  15. /***************************************************************************
  16.  *                                                                         *
  17.  *   This program is free software; you can redistribute it and/or modify  *
  18.  *   it under the terms of the GNU General Public License as published by  *
  19.  *   the Free Software Foundation; either version 2 of the License, or     *
  20.  *   (at your option) any later version.                                   *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. #ifndef SCRIBUSVIEW_H
  25. #define SCRIBUSVIEW_H
  26.  
  27. #include "styleoptions.h"
  28.  
  29. #include <vector>
  30. // include files for QT
  31. #include <QScrollArea>
  32. #include <QLineEdit>
  33. #include <QScrollBar>
  34. #if OPTION_USE_QTOOLBUTTON
  35.     #include <QToolButton>
  36. #else
  37.     #include <QPushButton>
  38. #endif
  39. #include <QMap>
  40. #include <QMenu>
  41. #include <QLabel>
  42. #include <QComboBox>
  43. #include <QProgressDialog>
  44. #include <QSpinBox>
  45. #include <QCursor>
  46. #include <QDragLeaveEvent>
  47. #include <QDragEnterEvent>
  48. #include <QDragMoveEvent>
  49. #include <QDropEvent>
  50. #include <QMouseEvent>
  51. #include <QPaintEvent>
  52. #include <QPoint>
  53. #include <QRect>
  54. #include <QRectF>
  55. #include <QTime>
  56. #include <QWheelEvent>
  57. #include <QRubberBand>
  58. #include <QList>
  59.  
  60. class QEvent;
  61. class QMimeData;
  62.  
  63. // application specific includes
  64. #include "observable.h"
  65. #include "scribusapi.h"
  66. #include "scribusdoc.h"
  67. #include "scrspinbox.h"
  68.  
  69. class Canvas;
  70. class CanvasMode;
  71. class CanvasGesture;
  72. class Hruler;
  73. class Vruler;
  74. class Page;
  75. class RulerMover;
  76. class PageSelector;
  77. class ScribusWin;
  78. class ScribusMainWindow;
  79. class UndoManager;
  80. class UndoTransaction;
  81. class TransactionSettings;
  82.  
  83.  
  84. /**
  85.  * This class provides an incomplete base for your application view.
  86.  */
  87.  
  88. class SCRIBUS_API ScribusView : public QScrollArea, public Observer<QRectF>
  89. {
  90.     Q_OBJECT
  91.  
  92. public:
  93.     ScribusView(QWidget* win=0, ScribusMainWindow* mw=0, ScribusDoc* doc=0);
  94.     ~ScribusView();
  95.     
  96.     friend class LegacyMode;
  97.     friend class CanvasMode_CopyProperties;
  98.     friend class CanvasMode_Edit;
  99.     friend class CanvasMode_EditGradient;
  100.     friend class CanvasMode_FrameLinks;
  101.     friend class CanvasMode_Magnifier;
  102.     friend class CanvasMode_NodeEdit;
  103.     friend class CanvasMode_Normal;
  104.     friend class CanvasMode_ObjImport;
  105.     friend class CanvasMode_Rotate;
  106.     
  107.     void requestMode(int appMode);
  108.     void startGesture(CanvasGesture*);
  109.     void stopGesture();
  110.     
  111.   /** Vergroesserungseingabefeld */
  112.     ScrSpinBox* zoomSpinBox; //zoom spinbox at bottom of view
  113.     PageSelector* pageSelector; //Page selector at bottom of view
  114.     RulerMover *rulerMover; //Widget between the two rulers for dragging the ruler origin
  115.     Hruler *horizRuler;
  116.     Vruler *vertRuler;
  117. #if OPTION_USE_QTOOLBUTTON
  118.     QToolButton *zoomDefaultToolbarButton;
  119.     QToolButton *zoomOutToolbarButton;
  120.     QToolButton *zoomInToolbarButton;
  121.     QToolButton *cmsToolbarButton;
  122.     QToolButton *previewToolbarButton;
  123. #else
  124.     QPushButton *zoomDefaultToolbarButton;
  125.     QPushButton *zoomOutToolbarButton;
  126.     QPushButton *zoomInToolbarButton;
  127.     QPushButton *cmsToolbarButton;
  128.     QPushButton *previewToolbarButton;
  129. #endif
  130.     QComboBox *layerMenu; //Menu for layers at bottom of view
  131.     QComboBox *unitSwitcher; //Menu for units at bottom of view
  132.     QComboBox *previewQualitySwitcher; //Menu for image preview quality
  133.     QComboBox *visualMenu;
  134.   /** Dokument zu dem die Seite gehoert */
  135.     ScribusDoc * const Doc;
  136.     Canvas * const m_canvas;
  137.     CanvasMode* m_canvasMode; // might be a CanvasGesture
  138.     QMap<int,CanvasMode*> modeInstances;
  139.     ApplicationPrefs * const Prefs;
  140.     UndoManager * const undoManager;
  141.     ScribusMainWindow* m_ScMW;
  142.     double OldScale;
  143.     double dragX,dragY,dragW,dragH;
  144.     double oldW;
  145.     int RotMode;
  146.     int DrHY;
  147.     int DrVX;
  148.     bool HaveSelRect;
  149.     //bool GroupSel;
  150.     bool DraggedGroup;
  151.     bool DraggedGroupFirst;
  152.     bool MidButt;
  153.     bool updateOn;
  154.     bool FirstPoly;
  155.     bool Magnify;
  156.     bool storedFramesShown;
  157.     bool storedShowControls;
  158.     int redrawMode;
  159.     int redrawCount;
  160.     PageItem *redrawItem;
  161.     QRubberBand *redrawMarker;
  162.     FPoint RCenter;
  163.     void updatesOn(bool on);
  164.     //CB This MUST now be called AFTER a call to doc->addPage or doc->addMasterPage as it
  165.     //does NOT create a page anymore.
  166.     Page* addPage(int nr, bool mov = true);
  167.  
  168.     void reformPages(bool moveObjects = true);
  169.     void updateLayerMenu();
  170.     void showMasterPage(int nr);
  171.     void hideMasterPage();
  172.     QImage PageToPixmap(int Nr, int maxGr, bool drawFrame = true);
  173.     QImage MPageToPixmap(QString name, int maxGr, bool drawFrame = true);
  174.     void RecalcPicturesRes();
  175.     void rulerMove(QMouseEvent *m);
  176.     /**
  177.      * Called when the ruler origin is dragged
  178.      * @param m mouse event
  179.      */
  180.     void setNewRulerOrigin(QMouseEvent *m);
  181. //    void FromHRuler(QMouseEvent *m);
  182. //    void FromVRuler(QMouseEvent *m);
  183. //    void SetYGuide(QMouseEvent *m, int oldIndex);
  184. //    void SetXGuide(QMouseEvent *m, int oldIndex);
  185. //     void getClosestGuides(double xin, double yin, double *xout, double *yout);
  186. //     bool ApplyGuides(double *x, double *y);
  187. //     void SnapToGuides(PageItem *currItem);
  188.     void getDragRectScreen(double *x, double *y, double *w, double *h);
  189.     void getGroupRectScreen(double *x, double *y, double *w, double *h);
  190. //    void ToView(QPainter *p);
  191. //    void ToView(QMatrix& m);
  192. //     bool MoveItem(double newX, double newY, PageItem* ite, bool fromMP = false);
  193.     bool PointOnLine(QPoint Start, QPoint Ende, QRect MArea);
  194.     void TransformPoly(int mode, int rot = 1, double scaling = 1.0);
  195. //    void Reset1Control();
  196. //    void ResetControl();
  197. //    void MoveClipPoint(PageItem *currItem, FPoint np);
  198. //     bool SizeItem(double newX, double newY, int ite, bool fromMP = false, bool DoUpdateClip = true, bool redraw = true);
  199. //     bool SizeItem(double newX, double newY, PageItem *pi, bool fromMP = false, bool DoUpdateClip = true, bool redraw = true);
  200. //    void moveGroup(double x, double y, bool fromMP = false, Selection* customSelection = 0);
  201. //     void MoveRotated(PageItem *currItem, FPoint npv, bool fromMP = false);
  202. //     bool MoveSizeItem(FPoint newX, FPoint newY, int ite, bool fromMP = false, bool constrainRotation=false);
  203. //    void RotateGroup(double win);
  204. //    void scaleGroup(double scx, double scy, bool scaleText=true, Selection* customSelection = 0);
  205. //     void RotateItem(double win, int ite);
  206. //     void RotateItem(double win, PageItem *currItem);
  207. //     void AdjustItemSize(PageItem *currItem);
  208.     bool slotSetCurs(int x, int y);
  209.     void HandleCurs(PageItem *currItem, QRect mpo);
  210. //    int HandleSizer(PageItem *currItem, QRect mpo, QMouseEvent *m);
  211.     bool GetItem(PageItem **b, int nr = -1);
  212.     void Deselect(bool prop = true);
  213.     void SelectItemNr(uint nr, bool draw = true, bool single = false);
  214.     void SelectItem(PageItem *pi, bool draw = true, bool single = false);
  215. //    void selectPage(QMouseEvent *m);
  216. //    bool SeleItem(QMouseEvent *m);
  217. //    void SetupDraw(int Nr);
  218. //    void SetupDrawNoResize(int nr);
  219.     void SetFrameRect();
  220.     void SetFrameRounded();
  221.     void SetFrameOval();
  222.     void PasteItem(struct CopyPasteBuffer *Buffer, bool loading, bool drag = false, bool noResize = true);
  223. //    void QueryFarben();
  224.     void rememberOldZoomLocation(int mx=0, int my=0);
  225.     bool groupTransactionStarted() { return m_groupTransactions > 0; }
  226. //    void setGroupTransactionStarted(bool isOn);
  227.     void startGroupTransaction(const QString &actionName = "",
  228.                                const QString &description = "",
  229.                                QPixmap *actionPixmap = 0,
  230.                                Selection* customSelection = 0);
  231.     void endGroupTransaction();
  232.     void cancelGroupTransaction();
  233.     void setScale(const double newScale);
  234.     double scale() const;
  235.  
  236.     virtual void changed(QRectF re);
  237.  
  238.     void updateCanvas(QRectF box = QRectF());
  239.     void updateCanvas(double x, double y, double width, double height) { updateCanvas(QRectF(x,y,width,height)); }
  240.     void setCanvasOrigin(double x, double y);
  241.     void setCanvasCenter(double x, double y);
  242.     void scrollCanvasBy(double deltaX, double deltaY);
  243.     FPoint canvasOrigin() const;
  244.     QRectF visibleCanvas() const;
  245.     
  246. private:
  247.     // legacy:
  248.     void updateContents(QRect box = QRect());
  249.     void updateContents(int x, int y, int w, int h);
  250.     void repaintContents(QRect box);
  251.     void resizeContents(int w, int h);
  252.     QPoint contentsToViewport(QPoint p);
  253.     QPoint viewportToContents(QPoint p);
  254. public: // for now
  255.     int contentsX();
  256.     int contentsY();
  257.     int contentsWidth();
  258.     int contentsHeight();
  259.     void setContentsPos(int x, int y);
  260.     int visibleWidth() { return viewport()->size().width(); } ;
  261.     int visibleHeight() { return viewport()->size().height(); } ;
  262.     void stopAllDrags();
  263.     void scrollBy(int x, int y);
  264.     void zoom(double scale = 0.0);
  265.     void zoom(int canvasX, int canvasY, double scale, bool preservePoint);
  266.  
  267. public slots: // Public slots
  268.     void languageChange();
  269.     void toggleCMS();
  270.     void switchPreviewVisual(int vis);
  271.     void togglePreview();
  272.     void unitChange();
  273.     void setRulersShown(bool isShown);
  274.     void slotUpdateContents();
  275.     void slotUpdateContents(const QRect &r);
  276.   /** Zooms in or out */
  277.     void slotZoom100();
  278.   /** Zooms in */
  279.     void slotZoomIn(int mx=0,int my=0);
  280.     void slotZoomOut(int mx=0,int my=0);
  281.   /** Redraws everything */
  282.     void DrawNew();
  283.     void setMenTxt(int Seite);
  284.     void setLayerMenuText(const QString &);
  285.     void GotoPa(int Seite);
  286.     void GotoLa(int l);
  287.     void GotoPage(int Seite);
  288.     void ChgUnit(int art);
  289.  
  290.     /*! \brief Change canvas preview quality for image items.
  291.     Called by previewQualitySwitcher (signal).
  292.     See void ScribusDoc::allItems_ChangePreviewResolution(int id)
  293.     for changing itself
  294.     */
  295.     void changePreviewQuality(int index);
  296.  
  297.     void SetCPo(double x, double y);
  298.     void SetCCPo(double x, double y);
  299.     void editExtendedImageProperties();
  300.     //void RefreshItem(PageItem *currItem);
  301.     void RefreshGradient(PageItem *currItem, double dx = 8, double dy = 8);
  302.     void ToggleBookmark();
  303.     void ToggleAnnotation();
  304. //     void sentToScrap();
  305.     void ToBack();
  306.     void ToFront();
  307.     void LowerItem();
  308.     void RaiseItem();
  309.     void ToPicFrame();
  310.     void ToPolyFrame();
  311.     void ToTextFrame();
  312.     void ToBezierFrame();
  313.     void ToPathText();
  314.     void FromPathText();
  315. //     void UniteObj();
  316. //     void SplitObj();
  317.     void Bezier2Poly();
  318.     void PasteToPage();
  319. //    void PasteRecentToPage(int id);
  320.     void TextToPath();
  321.     void adjustCMS();
  322. //    void adjustCanvas(double width, double height, double dX=0.0, double dY=0.0);
  323.     
  324. private: // Private attributes
  325.     int m_previousMode;
  326.     QMenu *pmen3;
  327.     QMenu *pmenResolution;
  328.     QMenu *cmsAdjustMenu;
  329.     QAction *idCmsAdjustMenu;
  330.     QPoint m_pressLocation;
  331.     QTime m_moveTimer;
  332.     QTimer *m_dragTimer;
  333.     bool m_dragTimerFired;
  334.     bool Ready;
  335.     int  oldX;
  336.     int  oldY;
  337.     int  m_groupTransactions;
  338.     int m_oldCanvasHeight;
  339.     int m_oldCanvasWidth;
  340.     UndoTransaction*  m_groupTransaction;
  341.     bool _isGlobalMode;
  342. //    bool forceRedraw;
  343.  
  344.     double oldItemX;
  345.     double oldItemY;
  346.  
  347. private slots:
  348.     void setZoom();
  349.     /**
  350.      * Called to update the GUI when the canvas(view) scrollbars are moved
  351.      * @param x 
  352.      * @param y 
  353.      */
  354.     void setRulerPos(int x, int y);
  355.     void selectionChanged();
  356.     void setObjectUndoMode();
  357.     void setGlobalUndoMode();
  358.     void dragTimerTimeOut();
  359.  
  360. public:
  361.     virtual void wheelEvent ( QWheelEvent *ev );
  362.     virtual void changeEvent(QEvent *e);
  363.  
  364.     void keyPressEvent(QKeyEvent *k);
  365.     void keyReleaseEvent(QKeyEvent *k);
  366.  
  367.     inline void registerMousePress(QPoint p);
  368.     bool mousePressed();
  369.     void resetMousePressed();
  370.     inline QPoint mousePressLocation();
  371.     inline bool moveTimerElapsed();
  372.     inline void resetMoveTimer();
  373.     
  374.     inline void startDragTimer();
  375.     inline void stopDragTimer();
  376.     inline void resetDragTimer();
  377.     inline bool dragTimerElapsed();
  378.  
  379.     bool handleObjectImport(QMimeData* mimeData, TransactionSettings* trSettings = NULL);
  380.  
  381. protected: // Protected methods
  382.     virtual void enterEvent(QEvent *);
  383.     virtual void leaveEvent(QEvent *);
  384.     virtual void resizeEvent ( QResizeEvent * event );
  385.     bool eventFilter(QObject *obj, QEvent *event);
  386.  
  387.     // those appear to be gone from QScrollArea:
  388.     virtual void contentsDragEnterEvent(QDragEnterEvent *e);
  389.     virtual void contentsDragMoveEvent(QDragMoveEvent *e);
  390.     virtual void contentsDragLeaveEvent(QDragLeaveEvent *e);
  391.     virtual void contentsDropEvent(QDropEvent *e);
  392.     virtual void setHBarGeometry(QScrollBar &bar, int x, int y, int w, int h);
  393.     virtual void setVBarGeometry(QScrollBar &bar, int x, int y, int w, int h);
  394.     void scrollContentsBy(int dx, int dy);
  395.     
  396.     //The width of vertical ruler/height of horizontal ruler, set to 17 in scribusview.cpp
  397.     int m_vhRulerHW;
  398.  
  399. signals:
  400.     void changeUN(int);
  401.     void changeLA(int);
  402.     void ItemPos(double, double);
  403.     void HaveSel(int);
  404.     void ItemGeom(double, double);
  405.     void DocChanged();
  406.     void PolyOpen();
  407.     void PStatus(int, uint);
  408.     void SetAngle(double);
  409.     void SetSizeValue(double);
  410.     void SetLineArt(Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle);
  411.     void SetLocalValues(double, double, double, double);
  412. //    void ItemFarben(QString, QString, int, int);
  413. //    void ItemGradient(int);
  414. //    void ItemTrans(double, double);
  415. //    void ItemBlend(int, int);
  416.     void ItemTextAttr(double);
  417.     void ItemTextUSval(double);
  418.     void ItemTextCols(int, double);
  419.     void SetDistValues(double, double, double, double);
  420.     void ItemTextAbs(int);
  421.     void ItemTextFont(const QString&);
  422.     void ItemTextSize(double);
  423.     void ItemTextSca(double);
  424.     void ItemTextScaV(double);
  425.     void ItemTextBase(double);
  426.     void ItemTextOutline(double);
  427.     void ItemTextShadow(double, double);
  428.     void ItemTextUnderline(double, double);
  429.     void ItemTextStrike(double, double);
  430.     void ItemTextFarben(QString, QString, double, double);
  431.     void ItemTextStil(int);
  432.     //void ItemRadius(double);
  433.     void HasTextSel();
  434.     void HasNoTextSel();
  435.     void MVals(double, double, double, double, double, double, int);
  436.     void PaintingDone();
  437.     void LoadPic();
  438.     void StatusPic();
  439.     void AppendText();
  440.     void DoGroup();
  441.     //void DoUnGroup();
  442.     void CutItem();
  443.     void CopyItem();
  444.     void Amode(int);
  445.     void AddBM(PageItem *);
  446.     void DelBM(PageItem *);
  447.     void ChBMText(PageItem *);
  448.     void ToScrap(QString);
  449.     void LoadElem(QString, double, double, bool, bool, ScribusDoc *, ScribusView *);
  450.     void LevelChanged(uint);
  451.     void HavePoint(bool, bool);
  452.     void ClipPo(double, double);
  453.     void AnnotProps();
  454.     void EndNodeEdit();
  455.     void Hrule(int);
  456.     void Vrule(int);
  457.     //void EditGuides();
  458.     void MousePos(double, double);
  459.     void callGimp();
  460.     void signalGuideInformation(int, qreal);
  461. };
  462.  
  463.  
  464.  
  465.  
  466. inline void ScribusView::registerMousePress(QPoint p)
  467. {
  468.     m_pressLocation = p;
  469.     m_moveTimer.start();
  470.     m_dragTimerFired = false;
  471. }
  472.  
  473.  
  474. inline QPoint ScribusView::mousePressLocation()
  475. {
  476.     return m_pressLocation;
  477. }
  478.  
  479.  
  480. inline bool ScribusView::moveTimerElapsed()
  481. {
  482.     return (m_moveTimer.elapsed() > Prefs->moveTimeout);
  483. }
  484.  
  485.  
  486. inline void ScribusView::resetMoveTimer()
  487. {
  488.     m_moveTimer.start();
  489. }
  490.  
  491.  
  492. inline void ScribusView::startDragTimer()
  493. {
  494.     m_dragTimerFired = false;
  495.     m_dragTimer->setSingleShot(true);
  496.     m_dragTimer->start(1000);            // set Timeout for starting a Drag operation to 1 sec.
  497. }
  498.  
  499. inline void ScribusView::stopDragTimer()
  500. {
  501.     m_dragTimer->stop();
  502. }
  503.  
  504.  
  505. inline void ScribusView::resetDragTimer()
  506. {
  507.     m_dragTimerFired = false;
  508. }
  509.  
  510.  
  511. inline bool ScribusView::dragTimerElapsed()
  512. {
  513.     return m_dragTimerFired;
  514. }
  515.  
  516. #endif
  517.